<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"
           %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"
           %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"
           %><%@ taglib tagdir="/WEB-INF/tags" prefix="cohesion"
           %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ page contentType="text/html;charset=ISO-8859-1"
         %><html:html>
    <head>
        <title>Facturaci&oacute;n</title>
        <html:base/>

        <%@include file="../header/include.jsp" %>

    </head>
    <body>
        <div id="header"  class="ui-widget-header ui-corner-all">
            <h1><bean:message key="all.title"/></h1>
            <div id="menu">
                <ul id="nav">
                </ul>
            </div>
        </div>
        <div id="body_wrapper">
            <div id="body">
                <div id="split">
                    <div class="top"></div>
                    <div id="left">
                        <div id="content">
                            <div class="ui-widget-header ui-corner-top "> <h1>Facturaci&oacute;n</h1></div>
                            <div  class="ui-widget-content ui-widget">
                                <div style="float: right;margin: 1% 1% 1% 1%; clear: left;">
                                    <ul class="sf_admin_td_actions fg-buttonset fg-buttonset-single">
                                        <cohesion:actor actors="5"><li class="sf_admin_action_usuario"><html:link action="/APreFacturas.do" styleClass="fg-button-mini fg-button ui-state-default fg-button-icon-left"><span class="ui-icon ui-icon-arrowreturnthick-1-w"></span>Regresar a la lista</html:link></li></cohesion:actor>
                                    </ul>
                                </div>

                                <div class="list ui-grid-table ui-widget ui-corner-all ui-helper-reset ui-helper-clearfix">
                                    <logic:notEmpty name="msg">
                                        <div  class="ui-state-error">
                                            ${empty msg ? "" : msg}

                                        </div>

                                    </logic:notEmpty>

                                    <div id="form_container"><html:form styleId="F935475"
                                               action="/AFacturacion.do" method="post">
                                            <div  style="margin-bottom:10px;"  class="formRow <logic:notEmpty name="nombreError"> ui-state-error ui-corner-all</logic:notEmpty>">
                                                <div class="labelRow">
                                                    <label for="940930">Nombre</label>
                                                </div>
                                                <div class="inputRow">
                                                    <html:text styleId="940930" property="nombre" size="50"/>
                                                </div>
                                                <logic:notEmpty name="nombreError">
                                                    ${nombreError}
                                                </logic:notEmpty>
                                            </div>

                                            <div class="formRow <logic:notEmpty name="rifError"> ui-state-error ui-corner-all</logic:notEmpty>" style="margin-bottom:10px;">
                                                <div class="labelRow">
                                                    <label for="939164">RIF o C&eacute;dula<%-- Rif o Cedula --%></label>
                                                </div>
                                                <div class ="inputRow">
                                                    <html:text styleId="939164" property="rifCedula" size="50"/>
                                                </div>
                                                <logic:notEmpty name="rifError">
                                                    ${rifError}
                                                </logic:notEmpty>
                                            </div>

                                            <div class="formRow" style="margin-bottom:10px;" >
                                                <div class="labelRow">
                                                    <label for="940921">Raz&oacute;n Social<%-- Razon Social --%></label>
                                                </div>
                                                <div class ="inputRow">
                                                    <html:text styleId="940921" property="razon_Social" size="50"/>
                                                </div>
                                            </div>


                                            <div class="formRow <logic:notEmpty name="direccionError"> ui-state-error ui-corner-all</logic:notEmpty>" style="margin-bottom:10px;">
                                                <div class="labelRow">
                                                    <label for="940924">Direcci&oacute;n</label>
                                                </div>
                                                <div class="inputRow">
                                                    <html:textarea styleId="940924" property="direccion" cols="60" rows="5"></html:textarea>
                                                </div>
                                                <logic:notEmpty name="direccionError">
                                                    ${direccionError}
                                                </logic:notEmpty>
                                            </div>

                                            <div class="formRow" style="margin-bottom:10px;">
                                                <div class="labelRow">
                                                    <label for="940927">Tel&eacute;fono </label>
                                                </div>
                                                <div class="inputRow">
                                                    <html:text styleId="940927" property="telefono" size="50"/>
                                                </div>
                                            </div>

                                            <div class="formRow <logic:notEmpty name="codigoPostalError"> ui-state-error ui-corner-all</logic:notEmpty>" style="margin-bottom:10px;">
                                                <div class="labelRow">
                                                    <label for="939164">C&oacute;digo Postal<%-- Rif o Cedula --%></label>
                                                </div>
                                                <div class ="inputRow">
                                                    <html:text styleId="939164" property="codigoPostal" size="50"/>
                                                </div>
                                                <logic:notEmpty name="codigoPostalError">
                                                    ${codigoPostalError}
                                                </logic:notEmpty>
                                            </div>

                                            <div class="formRow <logic:notEmpty name="ciudadError"> ui-state-error ui-corner-all</logic:notEmpty>" style="margin-bottom:10px;">
                                                <div class="labelRow">
                                                    <label for="939164">Ciudad<%-- Rif o Cedula --%></label>
                                                </div>
                                                <div class ="inputRow">
                                                    <html:text styleId="939164" property="ciudad" size="50"/>
                                                </div>
                                                <logic:notEmpty name="ciudadError">
                                                    ${ciudadError}
                                                </logic:notEmpty>
                                            </div>


                                            <%--<p id="939164_C"><label for="939164">Rif o Cedula Rif o Cedula </label><html:text styleId="939164" property="rifCedula" size="30"/></p>
                                        <p id="940921_C"><label for="940921">Razon Social Razon Social </label><html:text styleId="940921" property="razon_Social" size="30"/></p>
                                        <p id="940924_C"><label for="940924">Direccion Direccion </label><html:textarea styleId="940924" property="direccion" cols="40" rows="5"></html:textarea></p>
                                        <p id="940927_C"><label for="940927">Telefono Telefono </label><html:text styleId="940927" property="telefono" size="30"/></p>
                                        <p id="940930_C"><label for="940930">Nombre Nombre </label><html:text styleId="940930" property="nombre" size="30"/></p>
                                            --%>


                                            <script>
                                                $(function() {
                                                    function log( message ) {
                                                        $( "<div/>" ).text( message ).prependTo( "#log" );
                                                        $( "#log" ).attr( "scrollTop", 0 );
                                                    }

                                                    $( "#productos" ).autocomplete({
                                                        source: "<html:rewrite action="APreListaProductoaAjax"/>",
                                                        minLength: 2,
                                                        select: function(event,ui) {
                                                        
                                                            if(!document.getElementById("row_"+ui.item.id)) {
                                                                $.ajax({
                                                                    url: '<html:rewrite action="AFormularioProducto"/>',
                                                                    data: 'idProducto='+ui.item.id,
                                                                    success: function(html) {
                                                                        $("#formularioTabla").after(html);
                                                                    }
                                                                })
                                                            }
                                                        
                                                        }
                                                    });
                                                });

                                                function getSelectionId(text, li) {
                                                    //alert (li.id);
                                                    if(!document.getElementById("row_"+li.id)){

                                                        new Ajax.Updater('formularioTabla', '<html:rewrite action="AFormularioProducto"/>', {
                                                            parameters: {idProducto: li.id},
                                                            insertion: "bottom"
                                                        });
                                                    }
                                                    $('autocomplete').value = '';
                                                    //$('row_'+li.id).remove();

                                                }
                                            </script>

                                            <div class="form_row" style="margin-bottom:10px;">
                                                <label for="productos">Productos: </label><br>
                                                <input id="productos" type="text" onclick="$('#productos').val('');return false;" size="50"/>
                                            </div>

                                            <table border="1">
                                                <thead class="ui-widget-header">
                                                    <tr>
                                                        <th class="ui-state-default ui-th-column">Producto</th>
                                                        <th class="ui-state-default ui-th-column">Disponible</th>
                                                        <th class="ui-state-default ui-th-column">Cantidad</th>
                                                        <th class="ui-state-default ui-th-column">Acci&oacute;n</th>
                                                    </tr>
                                                </thead>
                                                <tbody id="formularioTabla">
                                                    <% request.setAttribute("_vacio", new Object[0]);%>
                                                    <logic:iterate id="prodC" collection="${empty L_Productos ? _vacio : L_Productos}">
                                                        <tr id="row_${prodC.producto.idCatalogo}" class="<logic:notEmpty name='producto_${prodC.producto.idCatalogo}Error'> ui-state-error ui-corner-all</logic:notEmpty> sf_admin_row ui-widget-content">
                                                            <td>${prodC.producto.nombre}</td>
                                                            <td>${prodC.producto.cantidad}</td>
                                                            <td><input type="text" name="cantidad_${prodC.producto.idCatalogo}" size="3" value="${prodC.cantidad}"></td>
                                                            <td>
                                                                <ul class="sf_admin_td_actions fg-buttonset fg-buttonset-single">
                                                                    <li class="sf_admin_action_show"><a onclick="$('#row_${prodC.producto.idCatalogo}').remove()" class="fg-button-mini fg-button ui-state-default fg-button-icon-left"><span class='ui-icon ui-icon-trash'></span> Eliminar</a></li>
                                                                </ul>
                                                            </td>
                                                        </tr>
                                                    </logic:iterate>

                                                </tbody>
                                            </table>

                                            <br>
                                            <html:submit styleClass="fg-button-mini fg-button ui-state-default" style="padding: 5px 10px 5px 10px;">Guardar</html:submit>
                                        </html:form></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div id="right">


                        <%@include file="../administrador/VMenuAdmin.jsp" %>
                    </div>
                    <div class="clearer ui-helper-clearfix"></div>
                    <div class="bottom"></div>
                </div>
                <div class="clearer"></div>
            </div>
            <div class="clearer"></div>
        </div>
        <div id="end_body"></div>
        <div id="footer"> <%@include file="/footer/include.jsp" %> </div>
    </body>
</html:html>